import java.io.FileDescriptor;

/**
 * @Author FengHuan Wang
 * @Date 2025/3/11 10:37
 * @Version 1.0
 */

/**
 * 我的安全管理器
 */
public class MySecurityManager extends SecurityManager{

    /**
     * 禁止cmd
     * @param cmd   the specified system command.
     */
    @Override
    public void checkExec(String cmd) {
        throw new SecurityException("无权限：" + cmd.toString());
    }

    /**
     * 禁止读文件
     * @param file      the system-dependent filename.
     * @param context   a system-dependent security context.
     */
    @Override
    public void checkRead(String file, Object context) {
        if (file.contains("hutool")){
            return;
        }
        throw new SecurityException("无权限：" + file + context.toString());
    }

    /**
     * 禁止写文件
     * @param fd   the system-dependent file descriptor.
     */
    @Override
    public void checkWrite(FileDescriptor fd) {
        throw new SecurityException("无权限：" + fd.toString());
    }

    /**
     * 禁止连接网络
     * @param host   the host name port to connect to.
     * @param port   the protocol port to connect to.
     */
    @Override
    public void checkConnect(String host, int port) {
        throw new SecurityException("无权限：" + host.toString() + port);
    }
}
